<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2022/8/17
  Time: 9:47
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
  <head>
    <base href="${pageContext.request.contextPath}/">
    <title>$Title$</title>
    <style>
      table tr:nth-child(odd){
        background: lightgray;
      }
    </style>
  </head>
  <body>
  <h3 align="center">海淀区工商局组织机构管理系统</h3>
  <form action="add.jsp" method="post">
    <input style="margin-left: 570px" type="submit" value="添加组织机构">
    <table align="center">
      <tr style="background: darkgray">
        <th>组织机构名称</th>
        <th>负责人</th>
        <th>业务状态</th>
        <th>创建日期</th>
        <th>操作</th>
      </tr>
      <c:forEach items="${sessionScope.list}" var="orgnazition">
        <tr>
        <td>${orgnazition.name}</td>
        <td>${orgnazition.principalName}</td>
        <c:if test="${orgnazition.status==0}">
          <td>开启业务</td>
        </c:if>
        <c:if test="${orgnazition.status==1}">
          <td>暂停业务</td>
        </c:if>
        <td>${orgnazition.createDate}</td>
        <c:if test="${orgnazition.status==0}">
          <td><a href="javascript:void(0)" onclick="update('${orgnazition.id}','暂停')">暂停业务</a></td>
        </c:if>
        <c:if test="${orgnazition.status==1}">
          <td><a href="javascript:void(0)" onclick="update('${orgnazition.id}','开启')">开启业务</a></td>
        </c:if>
        </tr>
      </c:forEach>
    </table>
  </form>
  <div align="center"><span id="span"></span></div>
  <script src="jq/jquery.js"></script>
  <script>

    function update(id,status){
      if(confirm("确认"+status+"业务吗？")){
        $.getJSON(
                "UpdateServlet",
                {id:id,status:status},
                function (data) {
                  if (data) {
                    location.href='ListServlet?status='+status;
                  }else{
                    $('#span').text(status+"业务失败");
                  }
                }
        )
      }
    }

    $(function () {
      if(${sessionScope.msg==true}){
        alert("添加成功");
      }else if(${sessionScope.msg==false}){
        alert("添加失败");
      }
      ${sessionScope.remove("msg")}

      if(${sessionScope.status == "暂停"}){
        $('#span').text("暂停业务成功");
      }else if(${sessionScope.status == "开启"}){
        $('#span').text("开启业务成功");
      }else{
        $('#span').text("");
      }
      ${sessionScope.remove("status")}
    })
  </script>
  </body>
</html>
